package com.ido.login.service;

import com.ido.login.LoginRequest;
import com.ido.login.strategy.LoginContext;
import com.ido.login.strategy.LoginStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * Create by zoub
 * Date 2025/7/1 3:03 PM
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginContext loginContext;

    public <T> T login(LoginRequest loginRequest) {
        LoginStrategy loginStrategy = loginContext.getStrategy(loginRequest.getType());
        if (Objects.isNull(loginStrategy)) {
            throw new RuntimeException("未找到登录策略");
        }
        return (T) loginStrategy.login(loginRequest);
    }

}
